<include file="Public/header" /> 

<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
	<include file="Public/sidebar" /> 
	<!--左侧菜单//-->
	
	<!-- mainCon -->
	<div id="mainCon" class="mainCon">
		<h4>商品分类列表</h4>
		<div>
			<a href="<{:U('Admin/Shopping/addCate',array('k'=>4,'sk'=>11))}>" class="btn btn-default">添加分类</a>
		</div>
		<table class="table table-bordered table-hover">
			<tr>
				<th></th>
				<th>编号</th>
				<th>分类名称</th>
				<th>创建时间</th>
				<th>排序</th>
				<th>操作</th>
			</tr>

			<empty name="list">
				<tr><td colspan="6" style="text-align:center;color:#999">～暂无数据～</td></tr>
			<else /> 

				<foreach name="list" item="vo">
					<tr>
						<td>
							<a href="javascript:void(0)" title="展开" class="trigger" data-flag="r" data-id="<{$vo['id']}>">
								<i class="glyphicon glyphicon-chevron-right"></i>
							</a>
						</td>
						<td><{$vo['id']}></td>
						<td><{$vo['name']}></td>
						<td><{$vo['createtime']|date="Y-m-d H:i",###}></td>
						<td><{$vo['sort']}></td>
						<td>
							<a href="<{:U('Admin/Shopping/addSubCate',array('id'=>$vo['id'],'k'=>4,'sk'=>13))}>">添加子类</a>
							<a href="<{:U('Admin/Shopping/editCate',array('id'=>$vo['id'],'k'=>4,'sk'=>12))}>">编辑</a>
							<a href="javascript:void(0)" class="delAct" data-id="<{$vo['id']}>">删除</a>
						</td>
					</tr>
					
					<if condition="!empty($vo['sub'])">
						<foreach name="vo['sub']" item="svo">
							<tr class="pid-<{$vo['id']}> row-<{$svo['id']}> hide">
								<td></td>
								<td><{$svo['id']}></td>
								<td><{$svo['name']}></td>								
								<td><{$svo['createtime']|date="Y-m-d H:i",###}></td>
								<td><{$svo['sort']}></td>
								<td>
									<a href="<{:U('Admin/Shopping/editCate',array('id'=>$svo['id'],'k'=>4,'sk'=>12))}>">编辑</a>
									<a href="javascript:void(0)" class="delAct" data-id="<{$svo['id']}>">删除</a>
								</td>
							</tr>
						</foreach>
					</if>
					
				</foreach>
			
			</empty>
			
		</table>
		
		<div class="pagebar">
			<{$pager}>
		</div>
		
	</div>
	<!-- mainCon// -->
	
</div>
<!--主窗体//-->

<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
$(function(){
	
	$(".trigger").click(function(){
		var flag = $(this).attr("data-flag");
		var id = $(this).attr("data-id");
		if(flag == 'r'){
			$(this).attr("data-flag","d");
			$(this).attr("title","收起");
			$(this).html('<i class="glyphicon glyphicon-chevron-down"></i>');
			$(".pid-"+id).removeClass("hide");
		}else if(flag == 'd'){
			$(this).attr("data-flag","r");
			$(this).attr("title","展开");
			$(".pid-"+id).addClass("hide");
			$(this).html('<i class="glyphicon glyphicon-chevron-right"></i>');
		}
	});

	$(".delAct").click(function(){
		var that = this;
		layer.confirm('您是否确认删除该记录？删除后不可恢复！', {icon: 3, title:'提示'}, function(index){
			var itemid = $(that).attr("data-id");
			$.post("<{:U('Admin/Shopping/delCate')}>",{id:itemid},function(r){
				if(r.error == 1){
					layer.close(index);
					layer.alert(r.errmsg,{icon: 2});
				}else{
					window.location.reload();
				}
			});
		});
		return false;
	});
});
</script>

<include file="Public/footer" /> 